#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=300000, maxm=300000;

int max(int a, int b) {
	return a>b ? a : b;
}

class Graph {
	public:
		int n, m, ind[maxn+1], link[2*maxn-1], to[2*maxn-1], dep[maxn+1], f[maxn+1], sum[maxn+1];

		void addSide(int u, int v) {
			m++;
			to[m] = v;
			link[m] = ind[u];
			ind[u] = m;
		}

		void build(int o, int fa) {
			dep[o] = dep[fa]+1;
			f[o] = fa;
			for (int i=ind[o]; i; i=link[i]) {
				if (to[i]!=fa) {
					build(to[i], o);
				}
			}
		}

		void getSum(int o, int def[]) {
			sum[o] = def[o];
			for (int i=ind[o]; i; i=link[i]) {
				if (f[o]!=to[i]) {
					getSum(to[i], def);
					sum[o] += sum[to[i]];
				}
			}
		}
};

int solve(int o, int n, int m, Graph &g, int c[], int plan[][2]) {
	static bool book[maxm+1];
	int ret=-1;
	if (o<=m) {
		int temp;
		book[o] = true;
		temp=solve(o+1, n, m, g, c, plan);
		ret = temp>=0 ? max(ret, temp+1) : ret;
		book[o] = false;
		temp=solve(o+1, n, m, g, c, plan);
		ret = temp>=0 ? max(ret, temp) : ret;
		return ret;
	} else {
		static int def[maxn+1];
		for (int i=0; i<=n; i++) {
			def[i] = 0;
		}
		for (int i=1; i<=m; i++) {
			if (book[i]) {
				int u=plan[i][0], v=plan[i][1];
				if (g.dep[u]>g.dep[v]) {
					def[u]++, def[g.f[v]]--;
				} else {
					def[v]++, def[g.f[u]]--;
				}
			}
		}
		g.getSum(1, def);
		for (int i=1; i<=n; i++) {
			if (c[i]<g.sum[i]) {
				return -1;
			}
		}
		return 0;
	}
}

int main() {
	freopen("fake.in", "r", stdin);
	freopen("fake.out", "w", stdout);

	static int c[maxn+1], plan[maxm+1][2];
	static Graph g;
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i=1; i<=n; i++) {
		scanf("%d", c+i);
	}
	for (int i=1; i<n; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		g.addSide(u, v);
		g.addSide(v, u);
	}
	g.build(1, 0);

	for (int i=1; i<=m; i++) {
		scanf("%d %d", plan[i], plan[i]+1);
	}

	printf("%d", solve(1, n, m, g, c, plan));

	fclose(stdin);
	fclose(stdout);
	return 0;
}
